package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HistorySalary;
import com.ruoyi.system.service.IHistorySalaryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 历史薪资Controller
 * 
 * @author ruoyi
 * @date 2023-05-10
 */
@Controller
@RequestMapping("/system/hsalary")
public class HistorySalaryController extends BaseController
{
    private String prefix = "system/hsalary";

    @Autowired
    private IHistorySalaryService historySalaryService;

    @RequiresPermissions("system:hsalary:view")
    @GetMapping()
    public String salary()
    {
        return prefix + "/hsalary";
    }

    /**
     * 查询历史薪资列表
     */
    @RequiresPermissions("system:hsalary:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HistorySalary historySalary)
    {
        startPage();
        List<HistorySalary> list = historySalaryService.selectHistorySalaryList(historySalary);
        return getDataTable(list);
    }

    /**
     * 导出历史薪资列表
     */
    @RequiresPermissions("system:hsalary:export")
    @Log(title = "历史薪资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HistorySalary historySalary)
    {
        List<HistorySalary> list = historySalaryService.selectHistorySalaryList(historySalary);
        ExcelUtil<HistorySalary> util = new ExcelUtil<HistorySalary>(HistorySalary.class);
        return util.exportExcel(list, "历史薪资数据");
    }

    /**
     * 新增历史薪资
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存历史薪资
     */
    @RequiresPermissions("system:hsalary:add")
    @Log(title = "历史薪资", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HistorySalary historySalary)
    {
        return toAjax(historySalaryService.insertHistorySalary(historySalary));
    }

    /**
     * 修改历史薪资
     */
    @RequiresPermissions("system:hsalary:edit")
    @GetMapping("/edit/{historyId}")
    public String edit(@PathVariable("historyId") Long historyId, ModelMap mmap)
    {
        HistorySalary historySalary = historySalaryService.selectHistorySalaryByHistoryId(historyId);
        mmap.put("historySalary", historySalary);
        return prefix + "/edit";
    }

    /**
     * 修改保存历史薪资
     */
    @RequiresPermissions("system:hsalary:edit")
    @Log(title = "历史薪资", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HistorySalary historySalary)
    {
        return toAjax(historySalaryService.updateHistorySalary(historySalary));
    }

    /**
     * 删除历史薪资
     */
    @RequiresPermissions("system:hsalary:remove")
    @Log(title = "历史薪资", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(historySalaryService.deleteHistorySalaryByHistoryIds(ids));
    }
}
